package thermologic.gui;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;
import thermologic.core.Sample;

/**
 *
 * @author mrivadeneira
 */
public class SamplesDataModel extends AbstractTableModel
{
    protected static final int NUM_COLS = 3;
    
    private Sample[] samples;
    
    private String[] colHeaders;
    
    public SamplesDataModel()
    {
        colHeaders = new String[NUM_COLS];
        
        colHeaders[0] = java.util.ResourceBundle.getBundle("properties/language").
                            getString("thermologic.samplesTable.col1");
        
        colHeaders[1] = java.util.ResourceBundle.getBundle("properties/language").
                            getString("thermologic.samplesTable.col2");
        
        colHeaders[2] = java.util.ResourceBundle.getBundle("properties/language").
                            getString("thermologic.samplesTable.col3");
    }
    
    public int getRowCount()
    {
        int rowCount = 0;
        
        if(samples != null)
        {
            rowCount = samples.length;
        }
        
        return rowCount;
    }

    public int getColumnCount()
    {
        return NUM_COLS;
    }

    @Override
    public String getColumnName(int col)
    {
        return colHeaders[col];
    }
    
    public Object getValueAt(int row, int col)
    {
        String ret = "";
        
        SimpleDateFormat dateFormat = new SimpleDateFormat(
                    java.util.ResourceBundle.getBundle("properties/language").getString("thermologic.format.date")
                );
        
        SimpleDateFormat timeFormat = new SimpleDateFormat(
                    java.util.ResourceBundle.getBundle("properties/language").getString("thermologic.format.time")
                );
        
        if(samples != null)
        {
            switch(col)
            {
                case 0: ret = dateFormat.format(samples[row].getTimeStamp());
                        break;
                        
                case 1: ret = timeFormat.format(samples[row].getTimeStamp());
                        break;
                
                case 2: ret = "" + samples[row].getValue();        
                        break;
            }
        }
        
        return ret;
    }
    
    public void setSamples(Sample[] samples)
    {
        this.samples = samples;
        
    }
    
}
